//
//  HUANGWWFACEANDGESTUREViewController.m
//  HuangwwFaceAndGesture
//
//  Created by 2297711051@qq.com on 01/14/2020.
//  Copyright (c) 2020 2297711051@qq.com. All rights reserved.
//

#import "HUANGWWFACEANDGESTUREViewController.h"
#import "HuangwwFaceAndGestureTool.h"
#import "ReactiveObjC.h"
#import "NKColorSwitch.h"
#import <FuliBaseLibraryFramework/FuliBaseLibraryFramework.h>
#import "HuangwwFaceAndGestureHeader.h"
#import "Masonry.h"
@interface HUANGWWFACEANDGESTUREViewController ()
@property (strong, nonatomic) UILabel *switchLabel;
@property (strong, nonatomic) UIButton *gestureButton;

@property (strong, nonatomic) NKColorSwitch *switchBtn;
@end

@implementation HUANGWWFACEANDGESTUREViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.switchLabel = [[UILabel alloc]init];
    self.switchLabel.text = @"人脸识别";
    self.switchLabel.textColor = RGB16(0x333333);
    self.switchLabel.font = FULI_REGULAR_FONT_16;
    
    self.switchBtn = [[NKColorSwitch alloc] initWithFrame:CGRectMake(0, 0, 60, 20)];
    [self.switchBtn setTintBorderColor:kGlobalWarnColor];
    [self.switchBtn setOnTintColor:kGlobalMainColor];
    [[self openAuthID]subscribeNext:^(id  _Nullable x) {
        [self.switchBtn setOn:[x boolValue]];
    }];
    
    self.gestureButton = [UIButton fuliButtonWithAction:^(UIButton *button) {
        
        [HuangwwFaceAndGestureTool gestureRecognition];
    }];
   
    [self.gestureButton setTitle:@"手势识别" forState:(UIControlStateNormal)];
    [self.gestureButton setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
    self.gestureButton.titleLabel.font = FULI_REGULAR_FONT_16;
    [self.view addSubview:self.switchLabel];
    [self.view addSubview:self.switchBtn];
    [self.view addSubview:self.gestureButton];
    
    [self.switchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.view).offset(50);
        make.top.equalTo(self.view).offset(100);
        make.width.equalTo(@80);
        make.height.equalTo(@30);
    }];
    
    [self.switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.switchLabel.mas_right).offset(10);
        make.centerY.equalTo(self.switchLabel);
        make.width.equalTo(@40);
        make.height.equalTo(@30);
    }];
    
    [self.gestureButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.switchLabel);
        make.top.equalTo(self.switchLabel.mas_bottom).offset(10);
        make.width.height.equalTo(self.switchLabel);
    }];
    [[self.switchBtn rac_signalForControlEvents:(UIControlEventValueChanged)] subscribeNext:^(NKColorSwitch *switchBtn) {
        
        BOOL open = switchBtn.on;
        if (open) {
            @weakify(self);
            [[HuangwwFaceAndGestureTool FaceRecognition] subscribeNext:^(NSNumber *x) {
                @strongify(self);
                [self.switchBtn setOn:[x boolValue]];
            }];
        }else {
            [HuangwwFaceAndGestureTool faceRemoveAuthID];
        }
    }];
}

- (RACSignal *)openAuthID{
    return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        if (kGetUserDefaults(kAuthIDopen)) {
            [subscriber sendNext:@"1"];
        }else {
            [subscriber sendNext:@"0"];
        }
        [subscriber sendCompleted];
        return [RACDisposable disposableWithBlock:^{
            
        }];
    }];
}

@end
